<template>
	<view class="page">
		<view class="content" v-if="listShow">
			<view class="single">
				<text>线下领取点名称:</text>
				<text>{{address}}</text>
			</view>
			<view class="single">
				<text>手机号:</text>
				<text>{{$store.state.vx_u_info.Phone}}</text>
			</view>
			<view class="single">
				<text>所在地址:</text>
				<input class="uni-input" v-model="parmas.Address" placeholder="请输入地址" />
			</view>
			<view class="single">
				<text>领取时间:</text>
				<text>{{currentTime}}</text>
			</view>
			<view class="single">
				<text>领取数量:</text>
				<input class="uni-input" v-model="parmas.Count" placeholder="请输入领取数量" />
			</view>
			<button type="primary" @click="onSumbit">确定提交</button>
		</view>
		<view class="img" v-if="listShow==false">
			<image src="https://yun.shlxkj.info:44300/艾瑞测/小程序/static/img/pass.png" mode="aspectFit"></image>
			<view>线下领取点名称: {{address}}</view>
			<view>手机号: {{$store.state.vx_u_info.Phone}}</view>
			<view>所在地址: {{parmas.Address}}</view>
			<view>领取时间: {{currentTime}}</view>
			<view>领取数量: {{parmas.Count}}</view>
		</view>
	</view>
	
	
	
</template>

<script>
	import {addReceive} from '@/utils/api.js'
	export default {
		data() {
			return {
				address: '',
				currentTime: '',
				parmas: {
					Name: '',
					Phone: this.$store.state.vx_u_info.Phone,
					Address: '',
					CreateTime: '',
					Count: null
				},
				listShow: true
			}
		},
		onLoad(op) {
			console.log(op);
			this.address = op.address
			this.parmas.Name = op.address
			this.getNewTime()
		},
		methods: {
			//获取当前时间
			getNewTime() {
				//new Date().getTime() 可以直接获取当前的时间戳
				this.nowTime = this.traversalTime(new Date().getTime()) 
				// console.log(this.traversalTime(new Date().getTime()), '当前时间')
			},
			addTimes(m) {
				return m < 10 ? '0' + m : m
			},
			traversalTime(timestamp) {
				//timestamp(时间戳)是整数，否则要parseInt转换
				let time = new Date(timestamp);
				let y = time.getFullYear();
				let m = time.getMonth() + 1;
				let d = time.getDate();
				let h = time.getHours();
				let mm = time.getMinutes();
				let s = time.getSeconds();
				this.currentTime = y + '-' + this.addTimes(m) + '-' + this.addTimes(d)
				this.parmas.CreateTime = y + '-' + this.addTimes(m) + '-' + this.addTimes(d) + ' ' + this.addTimes(h) + ':' + this.addTimes(mm) + ':' + this.addTimes(s)
			},
			async onSumbit(){
				if(this.parmas.Address != '' && this.parmas.Count != null){
					const res = await addReceive(this.parmas)
					console.log(res);
					if(res.Code == 200){
						this.listShow = false
					}
				}else{
					uni.showToast({
						title: '请输入正确信息',
						icon: 'error'
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding: 30rpx;
		font-size: 40rpx;

		.single {
			display: flex;
			margin-bottom: 40rpx;

			text {
				display: block;
				margin-right: 40rpx;
			}
		}
	}
	// .img{
	// 	width: 200rpx;
	// 	image{
	// 		width: 100%;
	// 		height: 100%;
	// 	}
	// }
</style>